package com.alexatguigu.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/create/{count}")
    public String createOrders(@PathVariable int count) {
        for (int i = 1; i <= count; i++) {
            String message = "订单-" + i;
            rabbitTemplate.convertAndSend("", "order.queue", message);
        }
        return "成功创建" + count + "个订单!";
    }
}
